package com.jack006.stock.task;

import com.jack006.stock.service.StockNewsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * @Classname TaskRecordStockNews
 * @Description 记录股票详情实时
 * @Date 2021-07-09 21:52
 * @Created by jack
 */
@Configuration
@EnableScheduling
public class TaskRecordStockNews {

    final static Logger logger = LoggerFactory.getLogger(TaskRecordStockNews.class);


    @Autowired
    private StockNewsService stockNewsService;

    /**
     * 添加定时任务
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    private void searchNews(){
        logger.info("开始执行定时实时数据采集任务:"+ LocalDateTime.now());
        long time = System.currentTimeMillis()/1000;
        // 调用文章 Service,把当前时间应该发布的定时文章
        stockNewsService.searchStockNews(time,1,20);

        logger.info("完成执行执行定时实时数据采集任务:");
    }

}
